﻿@model StudentPortal.Models.webpages_Group

@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="row-fluid">
    <div class="span12">
        <!-- BEGIN SAMPLE FORM PORTLET-->
        <div class="portlet box blue">
            <div class="portlet-title">
                <h4><i class="icon-reorder"></i>Edit</h4>
                <div class="tools">
                    <a href="javascript:;" class="collapse"></a>
                    <a href="#portlet-config" data-toggle="modal" class="config"></a>
                    <a href="javascript:;" class="reload"></a>
                    <a href="javascript:;" class="remove"></a>
                </div>
            </div>
            <div class="portlet-body form">
                <!-- BEGIN FORM-->
                @using (Html.BeginForm("Edit", "Group", FormMethod.Post, new { @class = "form-horizontal", id = "groupForm" }))
                {
                    @Html.ValidationSummary(true)

                    @Html.HiddenFor(model => model.GroupId)

                    <div class="control-group">
                        @Html.LabelFor(model => model.GroupName, new { @class = "control-label" })
                        <div class="controls">
                            @Html.TextBoxFor(model => model.GroupName, new { @class = "medium m-wrap" })
                            @Html.ValidationMessageFor(model => model.GroupName)
                        </div>
                    </div>
                    <input type="hidden" name="RoleIds" />
                    <div class="control-group">
                        <label class="control-label">Quyền</label>
                        <div class="controls">
                            @(Html.Kendo().Grid<StudentPortal.Models.webpages_Roles>()
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(c => c.RoleId)
            .ClientTemplate("&nbsp;<input type='checkbox' class='checkRow' value='#= RoleId #'/>")
            .HeaderTemplate("<input type='checkbox' class='checkAll'/>")
            .Width(40)
            .Title("")
            .HeaderHtmlAttributes(new { style = "text-align:center" })
            .HtmlAttributes(new { style = "text-align:center" })
            .Filterable(false).Groupable(false).Sortable(false);
        columns.Bound(model => model.RoleName);
        columns.Bound(model => model.DisplayName);
    })
    .Groupable()
    .Pageable()
    .Sortable()
    .Events(e =>
    {
        e.DataBound("onDataBound");
    })
    .DataSource(
        dataSource => dataSource.Ajax()
            .Read(read => read.Action("Read", "Roles"))
    )
)
                        </div>
                    </div>
                    <div class="form-actions">
                        <button class="btn blue" type="submit">Save</button>
                        @Html.ActionLink("Cancel", "Index", new { }, new { @class = "btn" })
                    </div>
                }

            </div>
        </div>
    </div>
</div>
<script src="~/Scripts/jquery.b4byb0o.js""></script>
<script>

    function onDataBound(e) {
        $('.checkAll').updateCheckRow({
            changeElement: "$('.checkAll').parent()"
        });
    }

    $(document).ready(function () {
        $('.checkAll').initCheckAll({ changeElement: "$('.checkAll').parent()",selected: @Html.Raw(Json.Encode(ViewBag.selectedVals)) });
        
        $('#groupForm').submit(function () {

            $(this).find('[name="RoleIds"]').val( $('.checkAll').selectedIDsToString());
            $.ajax({
                url: '@Url.Action("Edit")',
                type: 'post',
                dataType: 'json',
                data: $(this).serialize(),
                success: function (o) {
                    alert(o.Message);
                    if (o.Status == 1)
                        location.href = o.Data.Redirect;
                }
            });
            return false;
        });
        
    });

    function gridRefresh() {
        $("#Grid").data("kendoGrid").dataSource.read();
    }
</script>
@*<div>
    @Html.ActionLink("Back to List", "Index")
</div>*@

@*@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}*@
